package drds.global_transaction.api.global_transaction_id_context;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GlobalTransactionIdContexts
{

	private static class ContextHolder
	{
		private static GlobalTransactionIdContext INSTANCE = new ThreadLocalGlobalTransactionIdContext();
	}

	//
	public static final String global_transaction_id_with_address_and_port_key = "global_transaction_id_with_address_and_port_key";

	private static GlobalTransactionIdContext globalTransactionIdContext = getGlobalTransactionIdContext();

	public static void bind(String globalTransactionIdWithAddressAndPort)
	{
		globalTransactionIdContext.put(global_transaction_id_with_address_and_port_key, globalTransactionIdWithAddressAndPort);
	}

	public static GlobalTransactionIdContext getGlobalTransactionIdContext()
	{
		return ContextHolder.INSTANCE;
	}

	public static String getGlobalTransactionIdWithAddressAndPort()
	{
		return globalTransactionIdContext.get(global_transaction_id_with_address_and_port_key);
	}

	public static boolean inGlobalTransaction()
	{
		return globalTransactionIdContext.get(global_transaction_id_with_address_and_port_key) != null;
	}

	public static String unbind()
	{
		return globalTransactionIdContext.remove(global_transaction_id_with_address_and_port_key);
	}

}
